<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文本搜索框效果</title>
    <style>
        input {
            color: hotpink;
        }
    </style>
</head>
<body>
    <input type="text" value="hahaha" id="search">
    <script>
        var search = document.getElementById('search');
        
        search.onfocus = function() {
            if (this.value === 'hahaha') {
                this.value = '';
            }
            this.style.color = 'black';
        }
        search.onblur = function() {
            if (this.value === '') {
                this.value = 'hahaha';
            }
            this.style.color = 'hotpink';
        }
    </script>
</body>
</html>